<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="输入关键词" style="margin-bottom:30px;" />

    <!--树形结构的显示-->
    <el-tree
      ref="tree"
      :data="subjectList"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
  import subjectApi from '@/api/edu/subject'
  export default {
    name: 'list',
    data() {
      return {
        filterText: '',
        subjectList: [],
        defaultProps: {
            children: 'children',
            label: 'title'
        },
      }
    },
    created() {
      this.getSubjectList();
    },
    methods: {
      filterNode(value, data){
        if(!value)return true;
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1;
      },

      //获取所有的节点数据
       async getSubjectList(){
        const {data} = await subjectApi.getSubjectListPage();
        this.subjectList = data.data;
      },

    },
    watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },
  }
</script>

<style scoped>

</style>
